 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Crystal.libs;
using Crystal.Libs;
using Microsoft.Xna.Framework.Graphics;

namespace Crystal.Mapping
{
    [Serializable]
    [MapComponent("WallCell", "A Cell Wall")]
    public class WallCell : CellBase
    {
        //Fields 
		private RotationEnum _XRotation; 
		public RotationEnum XRotation
		{
			get { return _XRotation; }
            set
            {
                _XRotation = value;
                this.CellPrimitive.SetRotation((int)XRotation, (int)YRotation, 0f);
            }
		}

        private RotationEnum _YRotation;
        public RotationEnum YRotation
        {
            get { return _YRotation; }
            set 
            { 
                _YRotation = value; 
                this.CellPrimitive.SetRotation((int)XRotation, (int)YRotation, 0f);
            }
        }
        
        //cTor
        public WallCell(Game game, MazePosition position)
            : base(game, position)
        {
            this.CellPrimitive.Rescale(Globals.CellSize);

            XRotation = CrystalConversions.IntToRotation(Globals.GlobalRandomizer.Next(0, 5));
            YRotation = CrystalConversions.IntToRotation(Globals.GlobalRandomizer.Next(0, 5));
        }

        //Methods
        public override void UpdateCell(GameTime time)
        {
        
        }
        public override void RenderCell()
        {
            Matrix[] transforms = new Matrix[Resources.CellWallModel.Bones.Count];
            Resources.CellWallModel.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in Resources.CellWallModel.Meshes)
            {
                foreach (Effect fx in mesh.Effects)
                {
                    fx.CurrentTechnique = fx.Techniques["ColorShade"];

                    fx.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * CellPrimitive.World);
                    fx.Parameters["View"].SetValue(Globals.GameCamera.View);
                    fx.Parameters["Projection"].SetValue(Globals.GameCamera.Projection);
                    fx.Parameters["Texture"].SetValue(Crystal.Libs.Resources.WallMap);

                    fx.Parameters["AmbientColor"].SetValue(Globals.AmbientLightColor);
                    fx.Parameters["AmbientLevel"].SetValue(Globals.AmbientLightLevel);
                }
                mesh.Draw();
            }
        }
    }
}
